

import fs from "fs"

export default class FileUtil {

    /**
     * 创建目录
     * @param {} path 
     */
    static createFolder(path) {
        fs.mkdirSync(path);
    }

    /**
     * 读取文件
     * @param {*} path 
     */
    static readFile(path) {
        if (!fs.existsSync(path)) {
            return undefined
        }
        return fs.readFileSync(path, { encoding: 'utf-8' });
    }

    /**
     * 写入文件
     * @param {} path 
     * @param {*} str 
     */
    static writeFile(path,fileName, str) {
        const state = fs.statSync(path);
        if (!state || !state.isDirectory()) {
            fs.mkdirSync(path);
        }
        fs.writeFileSync(path + '/' + fileName, str, 'utf8');
    }

    /**
     * 查看文件的状态
     * @param {} path 
     */
    static getFileState(path){
        return fs.statSync(path)
    }


}

